<template>
  <van-form @submit="onSubmit">
      <van-field
          v-model="editUser.currentValue"
          :name="editUser.editKey"
          :label="editUser.editName"
          :placeholder="'请输入' + editUser.editName"
          :rules="[{ required: true, message: '请填写新的' + editUser.editName }]"
      />
    <div style="margin: 16px;">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
</template>
靶场考试平台
<script setup lang="ts">
import { ref } from 'vue';
import { useRoute } from "vue-router";
import myAxios from "../plugins/myAxios.ts";
import router from "../config/route.ts";
import {showFailToast, showSuccessToast} from "vant";
import {getCurrentUser} from "../global/user.ts";

const route = useRoute();

const editUser = ref({
  editKey: String(route.query.editKey),
  editName: String(route.query.editName),
  currentValue: String(route.query.currentValue),
});

const onSubmit = async () => {
  const currentUser = getCurrentUser();
  const res = await myAxios.post('/user/update', {
    id: currentUser.id,
    [editUser.value.editKey]: editUser.value.currentValue,
  })
  if (res.code === 0) {
    showSuccessToast("修改成功!")
    router.back();
  } else {
    showFailToast("修改失败!")
  }
}
</script>

<style scoped>

</style>